# Maintainer: MVZ Labor Ludwigsburg <edv@mvz-labor-lb.de>
# vim: ft=bash

# Inspired by https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-gcab/PKGBUILD

_realname=msitools
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.101
pkgrel=1
pkgdesc="A set of programs to inspect and build Windows Installer (.MSI) files (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://wiki.gnome.org/msitools'
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcab"
         "${MINGW_PACKAGE_PREFIX}-libgsf")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-vala")
source=("https://download.gnome.org/sources/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.xz"
	"001-wixl-heat-rename-header.patch")
sha256sums=('0cc4d2e0d108fa6f2b4085b9a97dd5bc6d9fcadecdd933f2094f86bafdbe85fe'
            'b3c0bc13bd0bdd6db7d6649b2000613616499d3768c6ae0d76e400890db3d0c5')

prepare() {
  cd $srcdir/${_realname}-${pkgver}

  patch -Np1 -i ${srcdir}/001-wixl-heat-rename-header.patch
}

build() {
  [[ -d build-${MSYSTEM} ]] && rm -rf build-${MSYSTEM}
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/copyright" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/copyright"
}
